package top.tocchen.bookshop.controller;

import top.tocchen.bookshop.entity.User;
import top.tocchen.bookshop.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * @author tocchen
 * @date 2022/8/9 19:34
 * @since jdk 1.8
 **/
@Controller
public class RegisterController {
    @Autowired
    UserService userService;

    @RequestMapping("/toregister")
    public String toregister(){
        return "Register";
    }
    @RequestMapping("/register")
    @ResponseBody
    public String runRegister(User record){
        if (userService.findByName(record.getName())!=null){
            return "240";
        }
        int result = userService.insertSelective(record);
        if(result>0){
            return "300";
        }else {
            return "250";
        }
    }


    }
